package com.my.engine;

import java.io.IOException;
import java.io.InputStream;

import com.my.engine.DefaultRenderer;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;

public class Engine extends GLSurfaceView  {
	
	public static String TAG	= "ENGINE";	
	
	public static long lastTime = 0;
	
	protected static DefaultRenderer renderer;
	
	protected static DefaultActivity activity;
	
	public static int screenWidht;
	public static int screenHeight;

	public Engine(Context context, DefaultRenderer renderer) {
		super(context);
		
		activity = (DefaultActivity)context;
		
		getHolder().setFormat(PixelFormat.TRANSLUCENT);
		setEGLConfigChooser(8, 8, 8, 8, 16, 8);
		
		Engine.renderer = renderer;
		setRenderer(renderer);
		setRenderMode(RENDERMODE_CONTINUOUSLY);
		
		lastTime = System.currentTimeMillis();
		
		
	}
	
	public void loadImage() {
//		InputStream is;// = activity.getResources().openRawResource(activity.getResources().getIdentifier("nehe", "nehe", activity.getPackageName()));
////		System.out.println("ID-----> " + activity.getResources().getIdentifier("nehe", "nehe", activity.getPackageName()));
//		
//		Bitmap bitmap = null;
//		
//		try {
//			//BitmapFactory is an Android graphics utility for images
////			bitmap = BitmapFactory.decodeStream(is);
//		} finally {
//			//Always clear and close
//			try {
////				is.close();
//				is = null;
//			} catch (IOException e) {
//			}
//		}
	}
	
	public static native void init(int width, int height);
	
	public static native void run(float delta /*, float acc0, float acc1, float acc2*/);

	public static native void run3d(float delta);
	
	public static native void set2d(int width, int height);
	
	public static native void draw2d();
	
	@Override
	public void onPause() {
		super.onPause();
	}
	
	@Override
	public void onResume() {
		super.onResume();
	}
}
